<script type="text/javascript">
    var status = '<?php echo $_GET['status'];?>';
    if(status == '-1'){
        alert('fail:<?php echo $_GET['msg'];?>');
    }
    $("#version_set").on("hidden.bs.modal", function() {
        $(this).removeData("bs.modal");
    });
    function on_submit(){
        var title = $("#title").val();
        var version_id = $("#version_id").val();
        var download_url = $("#download_url").val();
        var upgrade_point = $("#upgrade_point").val();
        if(!title || !version_id || !download_url || !upgrade_point){
            alert('名称, 版本好，下载地址，升级提示 不能为空');
            return false;
        }
        var v_type = $('input[name="version[type]"]:checked').val();
        if(v_type == 0){
            $("#confirm_txt").val("");
            $("#cancel_txt").val("");
        }else if(v_type == 1){
            var confirm_txt = $("#confirm_txt").val();
            var cancel_txt = $("#cancel_txt").val();
            if(!confirm_txt || !cancel_txt){
                alert('确认按钮文本和取消按钮文本 不能为空');
                return false;
            }
        }else if(v_type == 2){
            $("#cancel_txt").val("");
            var confirm_txt = $("#confirm_txt").val();
            if(!confirm_txt){
                alert('确认按钮文本 不能为空');
                return false;
            }
        }
        $("#version_form").submit();
    }
</script>

<div class="tab-pane active" id="horizontal-form">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true" aria-label="Close">×</button>
        <h2 class="modal-title"><?php echo $pageTitle;?></h2>
    </div>

    <form class="form-horizontal" id="version_form" action="index.php?c=<?php echo $_REQUEST['c'];?>&m=<?php echo $_REQUEST['m'];?>" name="form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="id" id="id" value="<?php echo $id; ?>"/>
        <input type="hidden" name="submits" value="1"/>

        <div class="form-group" style="margin-top: 10px;">
            <label for="title" class="col-sm-2 control-label">名称</label>
            <div class="col-sm-6">
                <input type="text" name="version[title]" value="<?php echo $version['title'];?>" class="form-control" id="title" placeholder="名称">
            </div>
            <div class="col-sm-2">
                <p class="help-block">不能为空</p>
            </div>
        </div>
        <div class="form-group">
            <label for="app_id" class="col-sm-2 control-label">设备</label>
            <div class="col-sm-6">
                <div class="radio-inline">
                    <label><input type="radio" name="version[app_id]" value="1" <?php if($version['app_id'] == 1 || empty($version['app_id'])){ echo 'checked';} ?> onclick="sel_txt(1)" />android</label>
                </div>
                <div class="radio-inline">
                    <label><input type="radio" name="version[app_id]" value="2" <?php if($version['app_id'] == 2){ echo 'checked';} ?> onclick="sel_txt(2)" />ios</label>
                </div>
            </div>
        </div>
        <div class="form-group" style="margin-top: 10px;">
            <label for="version_id" class="col-sm-2 control-label">大版本号</label>
            <div class="col-sm-6">
                <input type="text" name="version[version_id]" value="<?php echo $version['version_id'];?>" class="form-control" id="version_id" placeholder="大版本号 eg:1.2">
            </div>
            <div class="col-sm-2">
                <p class="help-block">不能为空</p>
            </div>
        </div>
        <div class="form-group" style="margin-top: 10px;">
            <label for="version_mini" class="col-sm-2 control-label">小版本号</label>
            <div class="col-sm-6">
                <input type="text" name="version[version_mini]" value="<?php echo $version['version_mini'];?>" class="form-control" id="version_mini" placeholder="小版本号 eg:1">
            </div>
        </div>
        <div class="form-group">
            <label for="type" class="col-sm-2 control-label">是否升级</label>
            <div class="col-sm-6">
                <div class="radio-inline">
                    <label><input type="radio" name="version[type]" value="0" <?php if(empty($version['type'])){ echo 'checked';} ?> onclick="show_txt(0)"/>不升级</label>
                </div>
                <div class="radio-inline">
                    <label><input type="radio" name="version[type]" value="1" <?php if($version['type'] == 1){ echo 'checked';} ?> onclick="show_txt(1)"/>升级</label>
                </div>
                <div class="radio-inline">
                    <label><input type="radio" name="version[type]" value="2" <?php if($version['type'] == 2){ echo 'checked';} ?> onclick="show_txt(2)"/>强制升级</label>
                </div>
            </div>
        </div>

        <div class="form-group" id="d_confirm_txt" style="margin-top: 10px;<?php if($version['type']){ echo 'display: block;';}else{ echo 'display: none;';}?>">
            <label for="confirm_txt" class="col-sm-2 control-label">确认按钮</label>
            <div class="col-sm-6">
                <input type="text" name="version[confirm_txt]" value="<?php echo $version['confirm_txt'];?>" class="form-control" id="confirm_txt" placeholder="文本">
            </div>
            <div class="col-sm-2">
                <p class="help-block">不能为空</p>
            </div>
        </div>
        <div class="form-group" id="d_cancel_txt" style="margin-top: 10px;<?php if($version['type'] == 1){ echo 'display: block;';}else{ echo 'display: none;';}?>">
            <label for="cancel_txt" class="col-sm-2 control-label">取消按钮</label>
            <div class="col-sm-6">
                <input type="text" name="version[cancel_txt]" value="<?php echo $version['cancel_txt'];?>" class="form-control" id="cancel_txt" placeholder="文本">
            </div>
            <div class="col-sm-2">
                <p class="help-block">不能为空</p>
            </div>
        </div>

        <div class="form-group" style="margin-top: 10px;">
            <label for="prompt_num" class="col-sm-2 control-label">提示次数</label>
            <div class="col-sm-6">
                <input type="text" name="version[prompt_num]" value="<?php echo $version['prompt_num'];?>" class="form-control" id="prompt_num" placeholder="提示次数">
            </div>
        </div>
        <div class="form-group" style="margin-top: 10px;">
            <label for="download_url" class="col-sm-2 control-label">下载地址</label>
            <div class="col-sm-6">
                <input type="text" name="version[download_url]" value="<?php echo empty($id) ? "http://sj.qq.com/myapp/detail.htm?apkName=com.warmlight" : $version['download_url'];?>" class="form-control" id="download_url" placeholder="下载地址">
            </div>
        </div>
        <div class="form-group">
            <label for="upgrade_point" class="col-sm-2 control-label">升级提示</label>
            <div class="col-sm-8">
                <textarea name="version[upgrade_point]" id="upgrade_point" cols="50" rows="5" class="form-control"><?php echo empty($id) ? "我们有更好玩的内容
更新鲜的体验想与你见面~" : $version['upgrade_point'];?></textarea>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-2">
                <input type="button" onclick="on_submit()" name="btn" value="保存" class="btn btn-primary" />
                <input type="reset" name="reset" value="取消" class="btn btn-default"/>
            </div>
        </div>
    </form>

    <script type="text/javascript">
        var q_tishi = "我们有更好玩的内容\r\n" +
            "更新鲜的体验想与你见面~";
        var t_tishi = "于千万人中与你相识\r\n" +
            "想以更贴心的体验温暖你~";
        function sel_txt(type){
            var v_type = $('input[name="version[type]"]:checked').val();
            var upgrade_point = "";
            if(v_type == 0 || v_type == 1){
                upgrade_point = t_tishi;
            }else{
                upgrade_point = q_tishi;
            }
            if(type == 1){ //android
                $("#download_url").val("http://sj.qq.com/myapp/detail.htm?apkName=com.warmlight");
                $("#upgrade_point").val(upgrade_point);
            }else{
                $("#download_url").val("https://itunes.apple.com/cn/app/暖光/id1369656501?mt=8");
                $("#upgrade_point").val(upgrade_point);
            }
        }
        function show_txt(type){
            if(type == 0){
                $("#confirm_txt").attr("value","");
                $("#cancel_txt").attr("value","");
                $("#upgrade_point").val(t_tishi);

                $("#d_confirm_txt").hide();
                $("#d_cancel_txt").hide();

            }else if(type == 1){
                $("#confirm_txt").attr("value","升级去咯");
                $("#cancel_txt").attr("value","我再想想");
                $("#upgrade_point").val(t_tishi);

                $("#d_confirm_txt").show();
                $("#d_cancel_txt").show();

            }else if(type == 2){
                $("#confirm_txt").attr("value","好哒");
                $("#cancel_txt").attr("value","");
                $("#upgrade_point").val(q_tishi);

                $("#d_confirm_txt").show();
                $("#d_cancel_txt").hide();
            }
        }
    </script>
</div>

